//
//  NXLoginViewController.m
//  NordsonTesco
//
//  Created by mac on 16/7/5.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "NXLoginViewController.h"
#import "NXBeforeRegistController.h"
#import "NXLoginViewCell.h"
@interface NXLoginViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *pulltableView;
    NSMutableArray *listArray;
    NSArray *titleArray;

}
@property(nonatomic,strong)UIButton *selectBtn;
@property(nonatomic,strong)UIButton *secureBtn;
@property (nonatomic,retain) UITextField *phoneNum;
@property (nonatomic,retain) UITextField *password;
@end

@implementation NXLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    titleArray = @[@"用户名:",@"密    码:",@"验证码:"];
    _phoneNum = [[UITextField alloc]init];
    _password = [[UITextField alloc]init];

    [self setupNavigationBar];
    [self createUI];
}
//设置导航栏
- (void)setupNavigationBar
{
    // 颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    // 导航栏标题
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    title.text = @"会员登录";
    title.backgroundColor = [UIColor clearColor];
    title.textColor = [UIColor whiteColor];
    title.font = [UIFont systemFontOfSize:17];
    title.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = title;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"return"] style:UIBarButtonItemStylePlain target:self action:@selector(didBackAction)];
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"注册" forState:UIControlStateNormal];
    [button setFrame: CGRectMake(0, 0, 42, 22)];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(zhuceClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = barButtonItem;
}
-(void)didBackAction
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)zhuceClick
{
    NXBeforeRegistController *beforeVC = [[NXBeforeRegistController alloc]init];
    [self.navigationController pushViewController:beforeVC animated:YES];
}
-(void)createUI
{
    pulltableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScrernWidth, kScrernHeight-64) style:UITableViewStyleGrouped];
    pulltableView.delegate = self;
    pulltableView.dataSource = self;
    [pulltableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    pulltableView.backgroundColor = [UIColor whiteColor];
    pulltableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:pulltableView];
}
#pragma mark - Table view data source
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        
        return 3;
    }
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        
        return 80;
    }
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        
        UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScrernWidth, 80)];
        backView.backgroundColor = [UIColor whiteColor];
        
        UIButton *tijiaoButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 20, kScrernWidth-10*2, 40)];
        tijiaoButton.backgroundColor = [UIColor redColor];
        tijiaoButton.layer.cornerRadius = 5;
        tijiaoButton.titleLabel.font = [UIFont systemFontOfSize:15];
        [tijiaoButton setTitle:@"登录" forState:UIControlStateNormal];
        [tijiaoButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [tijiaoButton addTarget:self action:@selector(tijiClick) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:tijiaoButton];
        
        _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _selectBtn.frame = CGRectMake(14, CGRectGetMaxY(tijiaoButton.frame)+12.5, 16, 16);
//        _selectBtn.selected = YES;
        [_selectBtn setBackgroundImage:[UIImage imageNamed:@"check_hover"] forState:UIControlStateNormal];//check_hover
        [_selectBtn setBackgroundImage:[UIImage imageNamed:@"check"] forState:UIControlStateSelected];
        [_selectBtn addTarget:self action:@selector(selectClick) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:_selectBtn];
        UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(40,CGRectGetMaxY(tijiaoButton.frame)+10,60, 20)];
        //        contentLabel.backgroundColor = COLOR_THEME;
        contentLabel.textColor = [UIColor lightGrayColor];
        contentLabel.text = @"自动登录";
        contentLabel.font = [UIFont systemFontOfSize:14];
        contentLabel.numberOfLines = 0;
        [backView addSubview:contentLabel];
        
        UIButton *forgetBtn = [[UIButton alloc] initWithFrame:CGRectMake(kScrernWidth-85, CGRectGetMaxY(tijiaoButton.frame)+10, 80, 20)];
//        forgetBtn.backgroundColor = [UIColor redColor];
//        forgetBtn.layer.cornerRadius = 5;
        forgetBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [forgetBtn setTitle:@"忘记密码?" forState:UIControlStateNormal];
        [forgetBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [forgetBtn addTarget:self action:@selector(forgetClick) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:forgetBtn];
        return backView;
        
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        
        return 10;
    }
    
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *gView = [[UIView alloc]init];
    gView.frame = CGRectMake(0, 0, kScrernWidth, 10);
    gView.backgroundColor = greyHead_Color;
    return gView;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * tableCell = @"NXLoginViewCell";
    NXLoginViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableCell];
    
    if (cell==nil) {
        
        cell = [[[NSBundle mainBundle]loadNibNamed:@"NXLoginViewCell" owner:self options:nil]lastObject];
        
        cell.backgroundColor = [UIColor whiteColor];
        
    }
    UIView *lineViewt = [[UIView alloc] initWithFrame:CGRectMake(0, 43.5, kScrernWidth, 0.5)];
    lineViewt.backgroundColor = [UIColor lightGrayColor];
    [cell.contentView addSubview:lineViewt];
    cell.titLab.textColor = [UIColor colorWithRed:0.29 green:0.29 blue:0.29 alpha:1.00];
    cell.titLab.text = titleArray[indexPath.row];
    switch (indexPath.row) {
        case 0:
        {
//            cell.contLab.secureTextEntry =NO;
            self.phoneNum = cell.contLab;
            cell.contLab.placeholder = @"请输入手机号";
            cell.contLab.borderStyle = UITextBorderStyleNone;
        }
            break;
        case 1:
        {
            self.password = cell.contLab;
            cell.contLab.secureTextEntry =YES;
            cell.contLab.placeholder = @"密码";
            cell.contLab.borderStyle = UITextBorderStyleNone;
            _secureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            _secureBtn.frame = CGRectMake(kScrernWidth-40, 12 ,16, 16);
            [_secureBtn setBackgroundImage:[UIImage imageNamed:@"VIEW---OFF"] forState:UIControlStateNormal];
            [_secureBtn setBackgroundImage:[UIImage imageNamed:@"VIEW"] forState:UIControlStateSelected];
            [_secureBtn addTarget:self action:@selector(secureBtnClick) forControlEvents:UIControlEventTouchUpInside];
            [cell.contentView addSubview:_secureBtn];
        }
            break;
        case 2:
        {
//            cell.contLab.secureTextEntry =NO;
            cell.contLab.placeholder = @"图片验证码";
            cell.contLab.borderStyle = UITextBorderStyleNone;
        }
            break;
        default:
            break;
    }
    return cell;
    
}
-(void)secureBtnClick
{
    
    if (_secureBtn.selected==YES) {
        _secureBtn.selected = NO;
        self.password.secureTextEntry = YES;
    }
    else if (_secureBtn.selected==NO) {
        _secureBtn.selected = YES;
        self.password.secureTextEntry = NO;

    }
    
}
-(void)selectClick
{
    
    if (_selectBtn.selected==YES) {
        
        _selectBtn.selected = NO;
    }
    else if (_selectBtn.selected==NO) {
        _selectBtn.selected = YES;
        
    }
    
}
-(void)forgetClick
{
    NSLog(@"forgetClick");
}
-(void)tijiClick
{
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
